<?php
/**
 * class Users acts as the subject
 */
class Users implements SplSubject {
	/**
	 * holds 
	 * @var array
	 */
	protected $_observers = array();
	
	/**
	 * add a new observer
	 * @param SplObserver $objserver
	 * @return 
	 */
	public function attach(SplObserver $observer) {
		$this->_observers[] = $observer;
	}
	
	/**
	 * remove an observer
	 * @param SplObserver $observer
	 * @return 
	 */
	public function detach(SplObserver $observer) {
		foreach($this->_observers as $key => $obs) {
			if(get_class($obs) == get_class($observer)) {
				unset($this->_observers[$key]);
			}
		}
	}
	
	/**
	 * notify all observers
	 * @return 
	 */
	public function notify(){
		foreach($this->_observers as $observer) {
			$observer->update($this);
		}
	}
}
